<template>
	<view>
		<!-- <view class="top-tab-view">
			<view class="left-tab">
				<view @click="selectedTab('推荐')" class="tab-item" :class="tabSelected==='推荐'? 'tab-selected':''">推荐</view>
				<view @click="selectedTab('最新')" class="tab-item" :class="tabSelected==='最新'? 'tab-selected':''">最新</view>
				<view @click="selectedTab('近一个月')" class="tab-item" :class="tabSelected==='近一个月'? 'tab-selected':''">近一个月</view>
			</view>
			<view class="right-btn">
				<picker mode="date">
					<view>自选</view>
				</picker>
				<image src="../../static/logo.png"></image>
			</view>
		</view> -->
		<view class="list-view">
			<view class="list-item" v-for="item in list" :key="item.uid" @click="goDetails(item)">
				<view class="left">
					<image :src="item.coverFileName"></image>
				</view>
				<view class="right">
					<view class="title">
						<!-- <image src="../../static/logo.png" class="play-icon"></image> -->
						<view class="titleName">{{item.titleName}}</view>
					</view>
					<view class="from-and_date">
						<text v-if="item.origin">{{item.origin}}|</text>
						{{item.releaseTime}}
					</view>
				</view>
			</view>
		</view>
		<view class="isOver" v-if="isOver">{{ overText }}</view>
	</view>
</template>

<script>
	import * as topNewsList from '../../common/api/topNewsList.js'
	export default {
		data() {
			return {
				tabSelected: "最新",
				queryForm: {
					columnRecommendation: '是'
				},
				pageIndex: 1,
				pageSize: 10,
				total:0,
				isOver:false,
				overText:'---我是有底线的---',
				list: [],
				classify: "",
				classifyObj: {
					'头条资讯': 'fd41bbf8a61345bc8a22b499c9dcd046',
					'直播': '0b0a342d55a74c70ac53854a028b7803',
					'电视': '959930f21ddf443d9694a1b79168da4a',
					'广播': 'fa6b29bca3fa47a2919df7bc1b30b992',
				},
				codeObj: {
					'头条资讯': '1-TouTiaoZiXun',
					'健康陕西': '2-JKSX',
					'百姓健康栏目': '3-bxjkxllm',
					'健康知识': '4-jkzs',
					'科普资料': '5',
					'宣传活动': '6',
					'直播': '6-5',
					'电视': '3-3-dslm',
					'广播': '3-6-gb',
				},
				localdata: [],
				classes: undefined,
				map: {
					text: 'classifyName',
					value: 'uid'
				},
			}
		},
		onLoad(e) {
			// this.selectedTab('最新')
			this.classify = e.classifyName
			this.getList()
			//this.queryTreeByCode()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.classify + '列表'
			})
		},
		methods: {
			getList() {
				const param = {
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					classifyUid: this.classifyObj[this.classify],
					...this.queryForm
				}
				topNewsList.queryByPage(param).then(res => {
					// this.list = res.data.data.rows
					this.list = [...this.list,...res.data.data.rows]
					this.total = res.data.data.total;
					if (this.pageIndex * this.pageSize >= this.total) {
						this.isOver = true;
					}
				}).catch(error => {
					console.log(error)
				})
			},
			selectedTab(e) {
				this.tabSelected = e
				if (e === '推荐') {
					this.queryForm = {
						columnRecommendation: '是'
					}
				} else if (e === '最新') {
					this.queryForm = {}
				} else if (e === '近一个月') {
					this.queryForm = {}
				}
				this.getList()
			},
			goDetails(data) {
				uni.navigateTo({
					url: "/pages/details/details?uid=" + data.uid
				})
			},
			queryTreeByCode() {
				const param = {
					code: this.codeObj[this.classify],
				}
				topNewsList.queryTreeByCode(param).then(res => {
					// this.localdata = this.removeEmptyChildren(res.data.data)
					debugger
					this.localdata = res.data.data
					//debugger
				}).catch(error => {
					console.log(error)
				})
			},
			removeEmptyChildren(node) {
				node.map(item => {
					if (!item.children || item.children.length === 0) {
						delete item.children
					} else {
						let res = item.children
						this.removeEmptyChildren(res)
					}
				})
				return node
			},

			popupclosed() {
				setTimeout(() => {
					if (!this.isAllowClose) {
						this.$refs.picker.show()
					}
				}, 1)
			},
			pickerChange(e) {
				this.isAllowClose = true
				this.getList()
			}
		},
		// 下拉
		onReachBottom () {
			if (this.pageIndex * this.pageSize >= this.total) {
				this.isOver = true;
				return;
			} else {
				this.pageIndex++
				this.getList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: white;
		display: flex;
		flex-direction: column;
	}

	.top-tab-view {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 30rpx;

		.left-tab {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.tab-item {
				width: 140rpx;
				height: 48rpx;
				margin-left: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 24rpx;
				border-radius: 10rpx;
				background: #FAFAFA;
				color: #CCCCCC;
			}

			.tab-selected {
				background: #DAFCF6;
				color: #27A280;
			}
		}

		.right-btn {
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #CCCCCC;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 30rpx;
				margin-left: 10rpx;
			}
		}
	}


	.list-view {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding: 0 30rpx;
		box-sizing: border-box;

		.list-item {
			width: 100%;
			display: flex;
			padding: 30rpx 0;
			border-bottom: solid 1rpx #F5F7F7;

			.left {
				image {
					width: 180rpx;
					height: 135rpx;
					border-radius: 16rpx;
				}
			}

			.right {
				flex: 1;
				margin-left: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.title {
					width: 480rpx;
					color: #666666;
					font-size: 30rpx;
					font-weight: 500;
					display: flex;
					align-items: center;

					.play-icon {
						width: 26rpx;
						height: 20rpx;
						margin-right: 20rpx;
					}

					.titleName {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.from-and_date {
					color: #999999;
					font-size: 24rpx;
				}
			}
		}
	}
	::v-deep .input-value-border {
		border: none;
	}
	.isOver{
		text-align: center;
		font-size: 12px;
		color:#bbb;
		height:60rpx;
		line-height:60rpx;
	}
</style>